﻿using System;

namespace EmbeddedSharp.Core.Function.Statistics {
    public abstract class AbstractStatisticsNode : FuncNode {

        public AbstractStatisticsNode()
            : base() {
        }

        public override object Evaluate() {
            if (Parameters.Count == 0) {
                return "usage: mode(p1, p2, p3, ...)";
            }

            double[] p = new double[Parameters.Count];
            for (int index = 0; index < p.Length; index++) {
                p[index] = Convert.ToDouble(
                    Parameters[index].Evaluate());
            }

            StatisticsFunctions sf = new StatisticsFunctions(p);
            return this.Evaluate(sf);
        }

        protected abstract double Evaluate(StatisticsFunctions sf);
    }
}
